<!-- 添加地址 -->
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,maximum-scale=1">
    <title>序列号</title>
    <link rel="stylesheet" href="/static/app/css/common.css">
    <link rel="stylesheet" href="/static/app/css/MyTeam.css">
</head>
<body>
    <div class="container" id="content">
    	<div class="boxTop">
    		<header class="header">
                <!-- 路径 -->
                <!-- 路径 -->
                <!-- 路径 -->
                <!-- 路径 -->
                <!-- 路径 -->
                <!-- 路径 -->
                <!-- 返回到商家侧边栏 -->
       <a href="/static/app/html/index_shop.html" class="pic">
           <img src="/static/app/images/icon_back2.png" alt="">
       </a>
       <span class="choice">我的团队</span>
       <a href="javaScript:;" class="add">
            <img src="/static/app/images/tianjia.png" alt="">
       </a>
      </header> 
      <!--body-->
      <ul class="list" id="btn">
       <li class="active">我的分店</li>
       <li>我的员工</li>
      </ul>
      </div>
       <!--body-->        
       <!-- 等待数据渲染 -->
       <content class="show" id="shop"></content>
       <content id="employee"></content>
     </div>
</body>

<script src="/static/app/js/common/jquery-3.3.1.min.js"></script>
<script src="/static/app/js/common/commonUrl.js"></script>
<script src="/static/app/js/common/common.js"></script>
<script src="/static/app/js/common/template.js"></script>

<!-- // 商家列表模板引擎 -->
<!-- 以下模板引擎需要店铺token -->
<!-- 以下模板引擎需要店铺token -->
<!-- 以下模板引擎需要店铺token -->
<script id="shopTpl" type="text/html">
<%for(var i = 0; i < data.length; i++) {%>
 <a class="userinfo" href="/static/app/html/shopInfo_r.html?id=<%:=data[i].id%>">
 	<% var picUrl = ''; %>
	<% if (data[i].picture == null || data[i].picture == '') { %>
		<% picUrl = '/static/app/images/head.png'; %>
	<% } else { %>
		<% picUrl = data[i].picture; %>
	<% } %>
  <img src="<%:=picUrl%>" alt="图片" class="toux"/>
      <p><%:=data[i].shopname%></p>
  <img src="/static/app/images/jiantou.png" alt="图片" class="righthref"/>
 </a>
 <% } %>
</script>

<!-- 员工列表模板引擎 -->
<!-- 以下模板引擎需要员工token -->
<!-- 以下模板引擎需要员工token -->
<!-- 以下模板引擎需要员工token -->
<script id="employeeTpl" type="text/html">
 <%for(var i = 0; i < data.length; i++) {%>
  <a class="userinfo" href="/static/app/html/teamInfo.html?id=<%:=data[i].id%>" data-name='<%:=data[i].staffname%>'>
   <img src="/static/app/images/head.png" alt="图片" class="toux"/>
   <p><%:=data[i].staffname%></p>
   <img src="/static/app/images/jiantou.png" alt="图片" class="righthref"/>
  </a>
  <% } %>
 </script>

<script>
 var optistId=getCookie("loginUserId");
 var btn = document.getElementById('btn');
 var div = document.getElementById('content');
 var aLi = btn.getElementsByTagName('li');
 var aDiv = div.getElementsByTagName('content');
 var shopTpl = document.getElementById('shopTpl').innerHTML;
 var employeeTpl = document.getElementById('employeeTpl').innerHTML;
 var shopList = $('#shop');
 var employeeList = $('#employee');
 $('.add').click(function(){
 	window.location.href="/static/app/html/addTeamStaff.html";
 })
 // 万里接口
const distanceShop = global + '/v1.0/merchant/branchStoreList?merchantId=';
const distanceEmployee = global + '/v1.0/merchant/employeeList?shopId=';

	for(var i = 0;i<aLi.length;i++){
		aLi[i].index = i;
		aLi[i].onclick = function(){
			for(var i = 0;i<aLi.length;i++){
				aLi[i].className = '';
				aDiv[i].className = '';
			}
			this.className = 'active';
			aDiv[this.index].className = 'show';
		}				
 }

function tpl(Tpl, type, url, list) {
 $.ajax({
   url: url,
   type: type,
   dateType: 'json',
   success: function(msg) {  
    if(msg.code == 200) {
    	console.log(msg);
     var html = template(Tpl, msg);
     list.html(html);
    }
   }
  })
};

// 参数一：模板引擎
// 参数二：请求方式
// 参数三：请求地址
// 参数四：渲染位置
tpl(shopTpl, 'get', distanceShop + optistId, shopList);
tpl(employeeTpl, 'get', distanceEmployee + optistId, employeeList);
$('#employeeTpl a').click(function(){
	var personName = $(this).data('name');
	setCookie("personName",personName,30);
})
</script>
</html>